package com.ymxk.timestar.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.ymxk.timestar.activity.adapter.StarAtlasAdapter;
import com.ymxk.timestar.view.drag.DragDataEntity;
import com.ymxk.timestar.view.drag.StarAtlasLayout;
import com.ymxk.timestar.activity.star.GlideImageLoader;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;

import java.util.ArrayList;

/**
 * 摘星图、
 */
public class StarAtlasSelectActivity extends AppCompatActivity {

    private Context mContext;
    private final String TAG = StarAtlasSelectActivity.class.getSimpleName();

    public static void jumpTo(Context context) {
        Intent intent = new Intent(context, StarAtlasSelectActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_star_atlas_select);
        mContext = this;
        StarAtlasLayout starLayout = findViewById(R.id.starLayout);
        starLayout.setJustShowCenter(false);
        ArrayList<DragDataEntity> imageInfo = createTestImageInfos();
        StarAtlasAdapter adapter = new StarAtlasAdapter(this);
        adapter.getDatas().addAll(imageInfo);
        starLayout.setAdapter(adapter);
        //starLayout.setNewData(imageInfo);
        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                Log.e(TAG, "onItemClick: ");
                String url = imageInfo.get(i).thumbnailUrl;
                Toast.makeText(view.getContext(), "onItemClick:" + url, Toast.LENGTH_LONG).show();
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }
        });
    }

    /**
     * 创建测试数据、
     *
     * @return
     */
    @NonNull
    private static ArrayList<DragDataEntity> createTestImageInfos() {
        ArrayList<DragDataEntity> imageInfo = new ArrayList<>();
        for (int i = 0; i < 9; i++) {
            DragDataEntity info = new DragDataEntity();
            //info.setThumbnailUrl("https://oss.res.gomezsz.com/oss-res/time-res/uat/8f20f84104d14a2999c03abb9a3f7792.jpg");
            info.setThumbnailUrl("https://test-cos.gomezhe.com/oss-res/time-res/2ef561924c484668b4d46654881da087.jpg");
            imageInfo.add(info);
        }
        return imageInfo;
    }
}